package com.zhongyu.controller;

import com.zhongyu.pojo.Org;
import com.zhongyu.service.OrgService;
import com.zhongyu.vo.GoodsTypeVo;
import com.zhongyu.vo.OrgVo;
import com.zhongyu.vo.PageResult;
import com.zhongyu.vo.ResultVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;
/*
部门
 */
@RestController
@RequestMapping("/renshi/bumen/")
public class OrgController {
    @Resource
    private OrgService orgService;
    @GetMapping("/search/{pageNo}/{pageSize}")
    public ResultVo search(@PathVariable Integer pageNo, @PathVariable Integer pageSize, OrgVo orgVo){
        PageResult pageResult=orgService.searchAll(pageNo,pageSize,orgVo);
        return ResultVo.success(pageResult);

    }
    @GetMapping("/list")
  //  @RequiresPermissions("bumen:list")
    public ResultVo list(){
        List<Org> list= orgService.searchAll();
        return  ResultVo.success(list);

    }
    @PostMapping("/update")
   // @RequiresPermissions("bumen:update")
    public ResultVo update(@RequestBody Org org, HttpSession session) {
        try {
            orgService.update(org);
            return ResultVo.success("修改部门成功!");
        }catch (Exception ex){
            return ResultVo.failure("部门修改失败!",ex);
        }
    }

    @GetMapping("/del")
   // @RequiresPermissions("bumen:del")
    public ResultVo del(Integer id) {
        try {
            orgService.del(id);
            return ResultVo.success("删除部门成功!");
        } catch (Exception ex) {

            return ResultVo.failure("删除部门失败！", ex);
        }
    }
    @PostMapping("/add")
  //  @RequiresPermissions("bumen:add")
    public ResultVo add(@RequestBody Org org, HttpSession session){
         try{
             orgService.add(org);
              return ResultVo.success("添加部门成功!");
        }catch (Exception ex){
            return ResultVo.failure("添加部门失败!",ex);
        }
    }
}
